package com.hzit.bj1804.dianservice.controller;

import com.hzit.bj1804.dian.entity.Memberbase;
import com.hzit.bj1804.dian.vo.MemberPage;
import com.hzit.bj1804.dianservice.service.MemberbaseService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Date;

@Controller
public class MemberbaseController {
    @Autowired
    MemberbaseService memberbaseService;
    @RequestMapping("mseleteAll")
    @ResponseBody
    /**
     * 查询所有会员
     */
    public Object seleteAll(){

        return memberbaseService.seleteAll();
    }
    @RequestMapping("mseleteByNmae")
    @ResponseBody
    /**
     * 根据会员名称查询会员信息
     */
    public Object seleteByNmae(@RequestParam("mname")String mname){
        return memberbaseService.seleteByNmae(mname);
    }
    @RequestMapping("mseleteByTime")
    @ResponseBody
    /**
     * 根据注册时间查询会员信息
     */
    public Object seleteByTime(@RequestParam("starttime") Date starttime, @RequestParam("endtime") Date endtime, @RequestParam("mname") String mname){
        return memberbaseService.seleteByTime(starttime, endtime, mname);
    }
    @RequestMapping("mseleteByTimePage")
    @ResponseBody
    /**
     *根据注册时间查询会员信息并分页
     * @param
     * @return
     */
    public Object seleteByTimePage(@RequestParam("limit") int limit,@RequestParam("page") int page,@RequestParam("starttime") Date starttime, @RequestParam("endtime") Date endtime, @RequestParam("mname") String mname){
        return memberbaseService.seleteByTimePage(limit, page, starttime, endtime, mname);
    }
    @RequestMapping("minsert")
    @ResponseBody
    /**
     * 添加会员信息
     * @param memberbase
     * @return
     */
    public Object insert(@RequestBody Memberbase memberbase){
        return memberbaseService.insert(memberbase);
    }
    @RequestMapping("mseleteAllPage")
    @ResponseBody
    /**
     * 分页查询
     * @param memberbase
     * @return
     */
    public Object seleteAllPage(@RequestParam("limit") int limit,@RequestParam("page") int page){
        return memberbaseService.seleteAllAge(limit,page);
    }
    @RequestMapping("mupdate")
    @ResponseBody
    /**
     * 修改会员信息
     * @param memberbase
     * @return
     */
    public Object update(@RequestParam("mid") int mid,@RequestParam("mstatus")String mstatus){
        return memberbaseService.update(mid,mstatus);
    }

    /**
     * 根据会员名和密码判断是否和数据库一致
     * @param mname
     * @param mpassword
     * @return
     */
    @RequestMapping("mselect")
    @ResponseBody
    public Object select(@RequestParam("mname") String mname,@RequestParam("mpassword") String mpassword){
        return memberbaseService.select(mname,mpassword);
    }

    /**
     * 根据会员名来修改密码
     * @param mname
     * @param newmpassword
     * @return
     */
    @RequestMapping("updatePassword")
    @ResponseBody
    public Object updatePassword(@RequestParam("mname") String mname,@RequestParam("newmpassword") String newmpassword){
        return memberbaseService.updatePassword(mname,newmpassword);
    }

    /**
     * 通过会员ID来修改状态
     * @param mid
     * @return
     */
    @RequestMapping("mselectByMid")
    @ResponseBody
    public Object selectByMid(@RequestParam("mid") int mid){
        return memberbaseService.selectByMid(mid);
    }

}
